/**
 * 
 */
package com.hpe.business.controller;

import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hpe.business.qo.TicketReportQo;
import com.hpe.business.response.ListResponseResults;
import com.hpe.business.service.ITicketsReportService;
import com.hpe.business.vo.TicketReportVo;
import com.hpe.core.controller.BaseController;
import com.hpe.core.enums.ErrorCode;
import com.hpe.core.exception.BusinessException;

/**
 * 统计控制器
 * @author luolin
 *
 * @version $id:ReporterController.java,v 0.1 2016年1月8日 下午3:47:02 luolin Exp $
 */
@Controller
@RequestMapping("reporter")
public class ReporterController extends BaseController {
    /** 日志 */
    private static final Logger   LOGGER = Logger.getLogger(ReporterController.class);
    /** 车票统计服务接口 */
    @Resource(name = "ticketsReportService")
    private ITicketsReportService ticketsReportService;

    /**
     * 售票总量统计
     * @param qo {@link TicketReportQo}
     * @return 统计结果
     * @Author : luolin. create at 2016年1月8日 下午3:58:55
     */
    @RequestMapping(value = "ticketstotal", produces = "application/json;charset=UTF-8", consumes = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public ListResponseResults ticketsTotalReport(@RequestBody TicketReportQo qo) {

        LOGGER.info("【售票总量统计】qo = " + JSONObject.fromObject(qo));

        if (StringUtils.isBlank(qo.getSysChannel())) {
            LOGGER.warn("【参数sysChannel为空】");
            throw new BusinessException(ErrorCode.NULL_ARGUMENT, "sysChannel不能为空");
        }
        if (StringUtils.isBlank(qo.getDateBegin())) {
            LOGGER.warn("【参数dateBegin为空】");
            throw new BusinessException(ErrorCode.NULL_ARGUMENT, "dateBegin不能为空");
        }
        if (StringUtils.isBlank(qo.getDateEnd())) {
            LOGGER.warn("【参数dateEnd为空】");
            throw new BusinessException(ErrorCode.NULL_ARGUMENT, "dateEnd不能为空");
        }
        validateDate(qo.getDateBegin(), qo.getDateEnd());

        List<List<TicketReportVo>> results = ticketsReportService.ticketsTotalReport(qo);
        return new ListResponseResults(true, results);
    }

}
